<template>
    <div class="search-result">
        <van-list
  v-model:loading="loading"
  :finished="finished"
  finished-text="没有更多了"
  @load="onLoad"

>
  <van-cell v-for="item in list" :key="item.id" :title="item.title" />
</van-list>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import {getSearchResult} from "../../../api/search"
const list = ref([]);
    const loading = ref(false);
    const finished = ref(false);
    const  pageNum=ref(1)
const props=defineProps({
  searchText:{
    type:String
  }
})

    const onLoad =async () => {
      console.log(props.searchText);
      // 异步更新数据
const {data} =  await   getSearchResult({
        pageNumber:pageNum.value,
        q:props.searchText
      })

list.value=data.list
loading.value=false
if(data.list>0){
  pageNum.value=data.p_num
}else{
  finished.value=true
}
    };

</script>